package estore.model;

import java.io.Serializable;

public class Product implements Comparable<Product>, Serializable {
    private static final long serialVersionUID = 1L;
    private String id;
    private String name;
    private double price;
    private int stock;

    public Product(String id, String name, double price, int stock) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.stock = stock;
    }

    @Override
    public int compareTo(Product o) {
        return this.id.compareTo(o.id);
    }

    @Override
    public String toString() {
        return String.format("ID:%s | 名称:%s | 价格:%.2f元 | 库存:%d件",
                id, name, price, stock);
    }

    public String getId() { return id; }
    public String getName() { return name; }
    public double getPrice() { return price; }
    public int getStock() { return stock; }
    public void setStock(int stock) { this.stock = stock; }
}